package com.hlddz.venue_reservation.mapper;

import com.hlddz.venue_reservation.entity.Venue;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author MoShang
 * @since 2024年05月31日
 */
@Mapper
public interface VenueMapper extends BaseMapper<Venue> {

    @Select("select * from venue where venue_type = #{venueType}")
    @Results({
            @Result(column = "venue_id", property = "venueId", id = true),
            @Result(column = "venue_name", property = "venueName"),
            @Result(column = "venue_address", property = "venueAddress"),
            @Result(column = "venue_description", property = "venueDescription"),
            @Result(column = "opening_hours", property = "openingHours"),
            @Result(column = "venue_image", property = "venueImage"),
            @Result(column = "venue_capacity", property = "venueCapacity"),
            @Result(column = "venue_remain", property = "venueRemain"),
            @Result(column = "venue_type", property = "venueType")
    })
    List<Venue> getVenueListByType(String venueType);

    @Select("select venue_name from venue where venue_type = #{venueType}")
    String getVenueNameByType(String venueType);

    @Update("update venue set venue_remain = venue_remain - 1 where venue_id = #{venueId}")
    void updateVenueRemain(Integer venueId);

    @Select("select venue_remain from venue where venue_id = #{venueId}")
    Integer getVenueRemainById(Integer venueId);
}
